package view;


import java.awt.CardLayout;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.ImageIcon;

import javax.swing.Timer;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import model.ListTaskGroup;
import model.Task;
import model.TaskGroup;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Luci
 */

public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    public DefaultListModel groupModel = new DefaultListModel();
    public DefaultListModel taskModel = new DefaultListModel();
    public JList group = new JList(groupModel);
    public JList task = new JList(taskModel);
    private MyToolBar toolbar = new MyToolBar();
    public them createTask = new them();
    public CreateGroup createGroup = new CreateGroup();
    public CardLayout card = new CardLayout();
    
    
    private TaskGroup[] tg1 = 
            {new TaskGroup("Công ty","C:\\Users\\Luci\\Documents\\NetBeansProjects\\Task4\\Image\\create.png") ,
            new TaskGroup("Gia đình","C:\\Users\\Luci\\Documents\\NetBeansProjects\\Task4\\Image\\create.png")};
    private Timer time;
    public MainFrame() {
        initComponents();
        this.setVisible(true);
        group.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        pnMain.setLayout(card);
        toolbar.setBounds(2, 2, 750, 50);
        this.add(toolbar);
        pnGroup.add(group);
        pnMain.add(task, "task");
        pnMain.add(createTask, "createTask");
        pnMain.add(createGroup, "createGroup");
        card.show(pnMain, "createTask");
        group.setCellRenderer(new GroupCell());

        /*DefaultListModel model = new DefaultListModel();
        DefaultListModel model2 = new DefaultListModel();
        tg1[0].add(new Task("Họp phòng nhân sự",0,0,"Bàn về những điều chỉnh nhân sự trong tháng tới","Thuyết trình",new Date(),new Date()));
        tg1[0].add(new Task("Task 1.2",0,0,"Description 2","Note",new Date(),new Date()));
        tg1[0].add(new Task("Task 1.3",0,0,"Description 3","Note",new Date(),new Date()));
        m= new JList();
        n = new JList();
        m.setModel(model);
        model.addElement(tg1[0]);
        model.addElement(tg1[1]);
        
        pnGroup.add(m);
        n.setCellRenderer(new TaskCell());
        pnMain.add(n);
        n.setModel(model2);
        
        
        m.addListSelectionListener( new ListSelectionListener(){
            @Override
            public void valueChanged(ListSelectionEvent e) {
                //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                DefaultListModel model2 = (DefaultListModel)n.getModel();
                model2.removeAllElements();
                System.out.println(tg1[m.getSelectedIndex()].getSize());
                System.out.println(m.getSelectedIndex());
                for(int i = 0; i < tg1[m.getSelectedIndex()].getSize(); i++){
                    model2.addElement(tg1[m.getSelectedIndex()].getAt(i));
                }
               
            }
        });
        DefaultListModel model = new DefaultListModel();
        model.addElement(tg1[0]);
        model.addElement(tg1[1]);
        jList1 = new JList(model);
        jList1.setCellRenderer(new TaskGroupCell());
        jList1.setVisibleRowCount(4);
        
        //JScrollPane pane = new JScrollPane(jList1);
        System.out.println(tg1[0].getName());
        System.out.println(tg1[0].getIcon());
        //image.setImageObserver(jLabel8);
        JScrollPane pane = new JScrollPane(jList2);
        this.add(pane);
        this.pack();
        time = new Timer(5000, new Action2());
        time.setInitialDelay(300);
        System.out.println(time.getDelay());
        System.out.println(time.getInitialDelay());
        System.out.println(System.currentTimeMillis());
        time.start();*/
        
        
        
    }
    
    
    
    public JButton createButton(String icon, String description){
        JButton bt = new JButton();
        bt.setSize(38, 38);
        bt.setIcon( new ImageIcon(icon));
        bt.setToolTipText(description);
        return bt;
    }
    public void viewTask(TaskGroup tg){
        taskModel.removeAllElements();
        for(int i =0; i<tg.getSize(); i++){
            taskModel.addElement(tg.getAt(i));
        }
    }
    class Action2 implements ActionListener{

            @Override
            public void actionPerformed(ActionEvent e) {
                jDialog1.setVisible(!jDialog1.isVisible());
                System.out.println("Initial");
                //jLabel9.setText("//To change body of generated methods, choose Tools | Templates.");
                time.setDelay(10000);
                System.out.println(time.getInitialDelay());
                System.out.println(System.currentTimeMillis());
            }
            
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        pnAlarm = new javax.swing.JPanel();
        lbNameA = new javax.swing.JLabel();
        lbDescriptionA = new javax.swing.JLabel();
        lbDateStartA = new javax.swing.JLabel();
        lbDateEndA = new javax.swing.JLabel();
        lbPriorityA = new javax.swing.JLabel();
        lbStatusA = new javax.swing.JLabel();
        tfNameA = new javax.swing.JTextField();
        bt1A = new javax.swing.JButton();
        bt2A = new javax.swing.JButton();
        lbDateStart2A = new javax.swing.JLabel();
        lbDateEnd2A = new javax.swing.JLabel();
        lbPriority2A = new javax.swing.JLabel();
        lbStatus2A = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        pnGroup = new javax.swing.JPanel();
        pnMain = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        openMenuBar = new javax.swing.JMenuItem();
        saveMenuBar = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        jDialog1.setBounds(new java.awt.Rectangle(200, 200, 300, 300));

        lbNameA.setText("Tên");

        lbDescriptionA.setText("Nội Dung");

        lbDateStartA.setText("Ngày thực hiện");

        lbDateEndA.setText("Ngày kết thúc");

        lbPriorityA.setText("Độ ưu tiên");

        lbStatusA.setText("Trạng thái");

        tfNameA.setText("Họp phòng nhân sự");

        bt1A.setText("Nhắc lại");

        bt2A.setText("Xác nhận");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setText("Bàn về những điều chỉnh nhân sự trong tháng tới");
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout pnAlarmLayout = new javax.swing.GroupLayout(pnAlarm);
        pnAlarm.setLayout(pnAlarmLayout);
        pnAlarmLayout.setHorizontalGroup(
            pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAlarmLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnAlarmLayout.createSequentialGroup()
                        .addComponent(lbStatusA, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbStatus2A, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnAlarmLayout.createSequentialGroup()
                        .addComponent(lbDateStartA)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lbDateStart2A, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnAlarmLayout.createSequentialGroup()
                        .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(lbDescriptionA, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(pnAlarmLayout.createSequentialGroup()
                                    .addComponent(lbDateEndA)
                                    .addGap(6, 6, 6))
                                .addComponent(lbPriorityA, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(lbNameA, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfNameA, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(pnAlarmLayout.createSequentialGroup()
                                .addGap(153, 153, 153)
                                .addComponent(bt1A, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(43, 43, 43)
                                .addComponent(bt2A, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(lbPriority2A, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbDateEnd2A, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 336, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(169, Short.MAX_VALUE))
        );
        pnAlarmLayout.setVerticalGroup(
            pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAlarmLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNameA, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfNameA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbDescriptionA, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbDateStartA, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbDateStart2A, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbDateEndA, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbDateEnd2A, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbPriorityA, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbPriority2A, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbStatusA, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbStatus2A, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(pnAlarmLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt2A, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(bt1A, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32))
        );

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDialog1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(pnAlarm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDialog1Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(pnAlarm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        pnGroup.setBackground(new java.awt.Color(255, 255, 255));
        pnGroup.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 255)));
        pnGroup.setLayout(new java.awt.BorderLayout());

        pnMain.setBackground(new java.awt.Color(255, 255, 255));
        pnMain.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 255)));

        javax.swing.GroupLayout pnMainLayout = new javax.swing.GroupLayout(pnMain);
        pnMain.setLayout(pnMainLayout);
        pnMainLayout.setHorizontalGroup(
            pnMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 517, Short.MAX_VALUE)
        );
        pnMainLayout.setVerticalGroup(
            pnMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 343, Short.MAX_VALUE)
        );

        fileMenu.setText("File");

        openMenuBar.setText("Open");
        fileMenu.add(openMenuBar);

        saveMenuBar.setText("Save");
        fileMenu.add(saveMenuBar);

        jMenuBar1.add(fileMenu);

        jMenu2.setText("Option");

        jMenuItem1.setText("Setting");
        jMenu2.add(jMenuItem1);

        jMenuItem2.setText("Alarm");
        jMenu2.add(jMenuItem2);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnGroup, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(55, 55, 55)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnGroup, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE)
                    .addComponent(pnMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt1A;
    private javax.swing.JButton bt2A;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JLabel lbDateEnd2A;
    private javax.swing.JLabel lbDateEndA;
    private javax.swing.JLabel lbDateStart2A;
    private javax.swing.JLabel lbDateStartA;
    private javax.swing.JLabel lbDescriptionA;
    private javax.swing.JLabel lbNameA;
    private javax.swing.JLabel lbPriority2A;
    private javax.swing.JLabel lbPriorityA;
    private javax.swing.JLabel lbStatus2A;
    private javax.swing.JLabel lbStatusA;
    private javax.swing.JMenuItem openMenuBar;
    private javax.swing.JPanel pnAlarm;
    private javax.swing.JPanel pnGroup;
    private javax.swing.JPanel pnMain;
    private javax.swing.JMenuItem saveMenuBar;
    private javax.swing.JTextField tfNameA;
    // End of variables declaration//GEN-END:variables
}
